#include "player.h"
#include "App.h"
#include "movieService.h"
#include "screen.h"
#include "stringUtils.h"
#include <codecvt>
#if CONFIG_AVFILTER
#endif
#include "MovieDownloader.h"

std::wstring UTF8ToUnicode(const std::string& str) {
	std::wstring ret;
	try {
		std::wstring_convert<std::codecvt_utf8<wchar_t>> wcv;
		ret = wcv.from_bytes(str);
	}
	catch (const std::exception& e) {
		std::cerr << e.what() << std::endl;
	}
	return ret;
}

void testCharset() {
	char arr[] = { 0x4A,0x61,0x6E,0x6E,0x69,0x6B,0x20,0x2D,0x20,0x48,0x65,0x61,0x72,0x74,0xC2,0xA0,0x4C,0x69,0x6E,0x6B,0x65,0x64 };
	std::wstring ws = StringUtils::utf8_2_wstr(arr, sizeof(arr));
	std::string utf8 = StringUtils::wstring2UTF8(ws.c_str(), ws.length());
}

int main(int argc, char* argv[]) {
	if (App::inst().alreadyRun()) {
		return 0;
	}
	App::inst().init();
	//MovieDownloader::loadClueCardInfo(11, L"1.8");
	Window* win = new Window();
	win->setBackground(true);
	win->create();
	

	int x,y, w, h;
	Screen::getSize(x, y, w, h);

	Player* player = new Player(true);
#if CONFIG_AVFILTER
#endif
	player->setWindow(win);
	win->setPosSize(x, y, w, h);

	PlayContext::initInstance(player);

	String path = MovieService::inst().startVideoFile();
	if (!path.empty()) {
		player->open(StringUtils::wstring2UTF8(path.c_str(),path.length()).c_str());
	}

	App::inst().event_loop();

	SDL_Quit();
	return 0;
}